'use strict';
const dayjs = require("dayjs");
module.exports = app => {
    const { INTEGER, STRING, TEXT } = app.Sequelize;
    const CourseItem = app.model.define(
      'CourseItem',
          {
              id: {type: INTEGER, primaryKey: true, autoIncrement: true},
              course_id: INTEGER,
              course_module_id: INTEGER,
              type: STRING,
              file_url: STRING,
              post_url: STRING,
              name: STRING,
              description: STRING,
              content: TEXT,
              duration:INTEGER,
              delete_flag: INTEGER,
              created_time: {
                  type: app.Sequelize.DATE,
                  get() {
                      return dayjs(this.getDataValue('created_time')).format('YYYY-MM-DD HH:mm:ss');
                  }
              },
              updated_time: {
                  type: app.Sequelize.DATE,
                  get() {
                      return dayjs(this.getDataValue('updated_time')).format('YYYY-MM-DD HH:mm:ss');
                  }
              }
          },
          {
              tableName: 'course_item',
              timestamps: true, // 启用时间戳(createdAt, updatedAt)
              updatedAt: 'updated_time', // 不想要 updatedAt
              createdAt: 'created_time', // 想要  createdAt 但是希望名称叫做 created_at
          }
    );
    return CourseItem;
};
